/** COPYRIGHT(C) 2008. Loc Phan. All Rights Reserved.
    A bankaccount class
    @author Loc Phan
    @version 1.01 2008-11-20
*/

package edu.sjsu.cs.phan;
/**
   A bank account has a balance that can be changed by 
   deposits and withdrawals.
*/
public class BankAccount
{  
   /**
      Constructs a bank account with a zero balance
      @param anAccountNumber the account number for this account
   */
   public BankAccount(int anAccountNumber)
   {   
      accountNumber = anAccountNumber;
      balance = 0;
   }

   /**
      Constructs a bank account with a given balance
      @param anAccountNumber the account number for this account
      @param initialBalance the initial balance
   */
   public BankAccount(int anAccountNumber, double initialBalance)
   {   
      accountNumber = anAccountNumber;
      balance = initialBalance;
   }

   /**
      Gets the account number of this bank account.
      @return the account number
   */
   public int getAccountNumber()
   {   
      return accountNumber;
   }

   /**
      Deposits money into the bank account.
      @param amount the amount to deposit
      (Precondition amount >= 0)
   */
   public void deposit(double amount)
   {  
      assert amount >= 0;
      double newBalance = balance + amount;
      balance = newBalance;
   }

   /**
      Withdraws money from the bank account.
      @param amount the amount to withdraw
      (Precondition amount >= 0 and amount <= balance)
   */
   public void withdraw(double amount)
   {   
      assert amount >= 0 && amount <= balance;
      double newBalance = balance - amount;
      balance = newBalance;
   }

   /**
      Gets the current balance of the bank account.
      @return the current balance
   */
   public double getBalance()
   {   
      return balance;
   }

   private int accountNumber;
   private double balance;
}
